/*
 * @Author: Shane
 * @Date: 2022-05-31 13:26:34
 * @LastEditTime: 2022-12-13 20:23:11
 * @LastEditors: Shane
 * @Description: 
 * @FilePath: /kkhttp/test/supmea_http_test.dart
 */

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:kk_http/kk_http_cfg.dart';
import 'package:kk_http/kk_http_client.dart';
import 'package:kk_http/kk_http_method.dart';

void main() {
  test('adds one to input values', () {});

  test('http get', () async {
    KKHttpCfg cfg = KKHttpCfg(baseUrl: 'https://httpbin.org/');
    KKHttpClient client = KKHttpClient(cfg: cfg);

    Response res = await client.request(
      HttpMethod.get,
      'get',
      queryParameters: {'name': '张三'},
    );
    debugPrint(res.toString());
  });
  test('http post', () async {
    KKHttpCfg cfg = KKHttpCfg(baseUrl: 'https://httpbin.org/');
    KKHttpClient client = KKHttpClient(cfg: cfg);

    Response res = await client.request(
      HttpMethod.post,
      'post',
      data: {'name': '张三'},
    );
  });

  test(
    'http cancle request',
    () {
      KKHttpCfg cfg = KKHttpCfg(baseUrl: 'https://httpbin.org/');
      KKHttpClient client = KKHttpClient(cfg: cfg);

      String key = 'KKPOSTKEY';
      client
          .request(HttpMethod.post, 'post', data: {'name': '张三'}, key: key)
          .then((value) {
        debugPrint('*******');
        debugPrint(value.toString());
      });
      client.cancelRequest(key, isFinished: false);
    },
  );
  test(
    'http cancle all request',
    () {
      KKHttpCfg cfg = KKHttpCfg(baseUrl: 'https://httpbin.org/');
      KKHttpClient client = KKHttpClient(cfg: cfg);

      String key = 'KKPOSTKEY';
      client
          .request(HttpMethod.post, 'post', data: {'name': '张三'}, key: key)
          .then((value) {
        debugPrint('*******');
        debugPrint(value.toString());
      });
      String key1 = 'KKPOSTKEY1';

      client
          .request(HttpMethod.put, 'put', data: {'name': '张三'}, key: key1)
          .then((value) {
        debugPrint('*******');
        debugPrint(value.toString());
      });

      String key2 = 'KKPOSTKEY2';
      client
          .request(HttpMethod.get, 'get', data: {'name': '张三'}, key: key2)
          .then((value) {
        debugPrint('*******');
        debugPrint(value.toString());
      });

      client.clear();
    },
  );
}
